This page last changed on Oct 22, 2006 by jdeolive.

This section is a

Short introduction to Spring, and its role in GeoServer

.
Excerpt from the Spring Mission Statement.

  • Spring should be a pleasure to use
  • Your application code should not depend on Spring APIs
  • Spring should not compete with good existing solutions, but should foster integration. (For example, JDO, Toplink, and Hibernate are great O/R mapping solutions. We don't need to develop another one.)

Spring + GeoServer

In GeoServer Spring is a container, whose job is to house and manage components inside of the container. A component in Spring is referred to as a bean. Consider the following two GeoServer components / beans called GeoServer, and Data.

Spring is used as the glue which ties together GeoServer components managing the dependencies between them.

GeoServer.java
/**
 * Represents the running server as a whole.
 */
class GeoServer {

  GeoServer() {
     ...
  }
}
Data.java
/**
 * The GeoServer catalog.
 */
class Data {

  /** reference to server facade */
  GeoServer server;

  Data(GeoServer server {
    this.server = server;
  }

}

In the above, Data is dependent on GeoServer. This dependency is declared simply by adding a reference to a GeoServer to the constructor of Data. This form of dependency declaration is known as Inversion of Control (IOC).

In order for this dependency on GeoServer to be satisfied at runtime, we must describe the dependency to Spring. This is done with a Spring Context.

applicationContext.xml
<beans>

  <!-- declare the GeoServer component -->
  <bean id="geoServer" class="org.vfny.geoserver.global.GeoServer"/>

  <!-- declare the Data component with a dependency on geoServer -->
  <bean id="data" class="org.vfny.geoserver.global.Data">
    <constructor-arg ref="geoServer"/>
  </bean>

</beans>

The above context does the following:

  1. Creates an instance of GeoServer
  2. Creates an instance of Data
  3. Injects the instance of Data, with the instance of GeoServer

Taking the example one step further, consider a third component, called WFS, which is dependent on both the Data and GeoServer components:

WFS.java
/**
 * Web Feature Service.
 */
class WFS {

  GeoServer geoServer;
  Data data;

  WFS(GeoServer geoServer, Data data) {
    this.geoServer = geoServer;
    this.data = data;
  }

}
applicationContext.xml
<bean id="wfs">
    <constructor-arg ref="geoServer"/>
    <constructor-arg ref="data"/>
  </bean>

Spring will manage the above component declarations such that all dependencies are satisfied.

The following depicts GeoServer realized as a set of beans wired together with Spring.

Plug-in System

Beyond being a container to house GeoServer components, Spring is used as the primary plug-in mechanism. In GeoServer plug-ins are based off of the idea of extension points and extensions.

Extension Points

An Extension Point is an interface or abstract class that is intended to be implemented by plug-ins. Conceptually, an extension point is a place in GeoServer that is designed to be extended by plugins. Physically, an extension point is a java interface or an abstract class.

An example of an extension point in GeoServer is _GetMapProducer whose purpose it to output a map in a WMS GetMap request.

GetMapProducer.java
interface GetMapProducer {

    void produceMap(WMSMapContext map) throws WmsException;

    void writeTo(OutputStream out) throws ServiceException, IOException;

    String getContentType() throws java.lang.IllegalStateException;

    void abort();
}

An implementation of this interface is intended to produce a map in a specifc format.

Extensions

An Extension is an implementation of an extension point. It is an instance of the interface or abstract class declared by the extension point. An extension is made up of two parts:

  1. A concrete class implementing an extension point interface
  2. A spring bean declaration

Continuing with the GetMapProducer example consider the following class:

PNGMapProducer.java
class PNGMapProducer implements GetMapProducer {
  ...
}

As the name suggests the point of this class is to produce map in a png image format.

As states above, the second part of an extension is a spring bean declaration. The bean declaration tells the spring container about our extension so that it can be used by other code.

applicationContext.xml
<bean id="pngMapProducer" class="PNGMapProducer"/>

Reference

Spring Framework Reference


architecture.png (image/png)
dependency.png (image/png)
extension.png (image/png)
Document generated by Confluence on Jan 16, 2008 23:26